<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.commerceE.domain.User,com.commerceE.domain.Product_instance,java.util.*"%>
<%@ include file="includes.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<% String basePath = request.getContextPath();%>
<% String baseCSSPath = request.getContextPath()+"/resources/css";%>
<% String baseJSPath = request.getContextPath()+"/resources/js";%>
<% String baseImagePath = request.getContextPath()+"/resources/images";%>

<title>Account Login</title>

<link href="<%=baseImagePath%>/favicon.png" rel="icon">

<link href="<%=baseCSSPath%>/stylesheet.css" rel="stylesheet" type="text/css" >
<script src="<%=baseJSPath %>/jquery-1.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/jquery_004.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/script.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/common.js" type="text/javascript" ></script>

<script language="javascript">

function updateQuantityButton(productInstanceId){
	var quantity = document.getElementById("quantity_"+productInstanceId).value;
	if(isNaN(Number(quantity))){
		$('#notification').html('<div class="success" style="display: none;">Please type a valid number!<span><img src="resources/images/close.png" alt="" class="close" /></span></div>');
		$('.success').fadeIn('slow');
		$('#cart-total').html(json['total']);
	}else{
		window.location = "<%=basePath %>/shoppingCart/updateShoppingCartQuantity.html?productInstanceId="+productInstanceId+"&quantity="+quantity;
	}
}

function deleteFromShoppingCart(productInstanceId){
		window.location = "<%=basePath %>/shoppingCart/deleteFromShoppingCart.html?productInstanceId="+productInstanceId;
}

</script>

</head>

<body class="account-login">
	<div class="main-shining">
		
<p style="display: block;" id="back-top"> <a href="#top"><span></span></a> </p>
<div class="row-1">
    <%@ include file="header.jsp" %>
   </div>
<div id="container">
<div id="notification"> </div>
<div id="column-left">
   <%@ include file="navMenu.jsp" %>
 </div>
 
<div id="content">
 
       <div class="breadcrumb">
        <a href="">首页</a>
         » <a class="last" href="">我的购物车</a>
      </div>
 
      
      
      <%
List<Product_instance> productInstanceListOfSession = null;
if(currentUser!=null){
	productInstanceListOfSession = currentUser.getProductInstanceListOfSession();
}


if(productInstanceListOfSession==null || productInstanceListOfSession.size()==0){
%>
	 <div class="empty">您的购物车为空!</div>

<%
}else{
%>	
  <h1>我的购物车   </h1> 
    <div class="cart-info">
      <div class="shop-cart">
      <table>
        <thead>
          <tr>
            <td align="center" class="image">图片</td>
            <td align="center" class="name">商品名称</td>
            <td align="center" class="model">属性</td>
            <td align="center" class="quantity">数量</td>
            <td align="center" class="price">单价</td>
            <td align="center" class="total" style="border-right:none;">总计</td>
          </tr>
        </thead>
        <tbody>
    <%
	for(Product_instance productInstance : productInstanceListOfSession){
		double price = productInstance.getQuantity() * productInstance.getProduct().getDiscountPrice();
    %>
          <tr>
            <td class="image"><a href="product/productDetail.html?productId=<%=productInstance.getProduct().getProductId() %>"><img src="image_upload/<%=productInstance.getProduct().getBestBuyImage().getPath()%>" alt="Magna aliqua." title="<%=productInstance.getProduct().getProductName() %>"></a>
              </td>
            <td class="name"><a href="product/productDetail.html?productId=<%=productInstance.getProduct().getProductId() %>"><%=productInstance.getProduct().getProductName() %></a>
                            <div>
                              </div>
              </td>
            <td class="model" width="100px">颜色 : <%=productInstance.getColor_product_option_value().getDisplayValue() %>
		                  <br/>尺码: <%=productInstance.getSize_product_option_value().getDisplayValue() %>            
            </td>
            <td class="quantity"><input id="quantity_<%=productInstance.getProductInstanceId() %>" value="<%=productInstance.getQuantity() %>" size="1" type="text">
              
              <div class="wrapper mt5">
              <a onclick="updateQuantityButton(<%=productInstance.getProductInstanceId() %>)"><img src="<%=baseImagePath%>/update.png" alt="Update" title="Update"></a> &nbsp;
              <a onclick="deleteFromShoppingCart(<%=productInstance.getProductInstanceId() %>)"><img src="<%=baseImagePath%>/remove.png" alt="Remove" title="Remove"></a>
              </div>
              </td>
            <td class="price">¥<%=productInstance.getProduct().getDiscountPrice() %></td>
            <td class="total" style="border-right:0;">¥<%=price %></td>
          </tr>
     <%} %>   
          
         </tbody>
      </table>
          </div>
    </div>
  
   <div class="cart-bottom">
   <div class="cart-total">
    <table id="total">
    <tbody>
      <tr class="row-table-1">
        <td class="right cart-total-name last"><b>Total:</b></td>
        <td class="right cart-total1 last"><strong>¥<%=currentUser.getTotalPrice() %></td>
      </tr>
      </tbody></table>
  </div>
  <div class="buttons">
    <div class="right"><a href="shoppingCart/checkout_login.html" class="button"><span>付款</span></a></div>
    <div class="center"><a href="home.html" class="button"><span>继续购物</span></a></div>
  </div>
  </div>
  
   <%} %>
  
  </div>

</div>
<div class="footer-wrap">
	<%@ include file="footer.jsp" %>
</div>
 
</div>

</body></html>